package org.jeecg.modules.demo.hydrology.controller;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.demo.hydrology.dto.AnalysisListDto;
import org.jeecg.modules.demo.hydrology.dto.DhssDto;
import org.jeecg.modules.demo.hydrology.dto.LargeDto;
import org.jeecg.modules.demo.hydrology.entity.Analysis;
import org.jeecg.modules.demo.hydrology.entity.Cgkcdss;
import org.jeecg.modules.demo.hydrology.service.IAnalysisService;
import org.jeecg.modules.demo.hydrology.service.IDhssService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author zhouwenhao
 * @date 2024/5/15
 * @dec 描述
 */
@Api(tags="后台系统首页")
@RestController
@RequestMapping("/hydrology/analysis")
@Slf4j
public class AnalysisController {
    @Autowired
    private IAnalysisService analysisService;
    @ApiOperation(value="首页实时数据查询", notes="首页实时数据查询")
    @GetMapping(value = "/list")
    public Result<IPage<AnalysisListDto>> getList(@RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                                                  @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
                                                  @RequestParam(name="params", defaultValue="140421005184") String params,
                                                  HttpServletRequest req) {
        List<AnalysisListDto> analysisListDtoArrayList =analysisService.getAnalysisList(params);
        List<AnalysisListDto> pageData = analysisListDtoArrayList.stream()
                .skip((pageNo - 1) * pageSize) // 跳过前面不需要的页数
                .limit(pageSize) // 限制返回的条数
                .collect(Collectors.toList());
        IPage<AnalysisListDto> pageResult = new Page<>(pageNo, pageSize, analysisListDtoArrayList.size());
        pageResult.setRecords(pageData); // 设置当前页的数据
        return Result.ok(pageResult);
    }
    @ApiOperation(value="后台系统首页", notes="后台系统首页")
    @GetMapping(value = "/getTop")
    public Result<Analysis> getTop(@RequestParam(name="params",required=true) String paramsTime) {
        Analysis analysis= analysisService.getTop(paramsTime);
        return Result.OK(analysis);
    }
    @ApiOperation(value="后台系统首页BottomLeft", notes="后台系统首页BottomLeft")
    @GetMapping(value = "/getBottomLeft")
    public Result<List<String>> getBottomLeft() {
        List<String> category= analysisService.getBottomLeft();
        return Result.OK(category);
    }
    @ApiOperation(value="后台系统首页BottomRightTopLeft", notes="后台系统首页BottomRightTopLeft")
    @GetMapping(value = "/getBottomRightTopLeft")
    public Result<List<String>> getBottomRightTopLeft() {
        List<String> total= analysisService.getBottomRightTopLeft();
        return Result.OK(total);
    }
}
